R Tutorials by : Er Karan Arora : Founder & CEO - ITRONIX SOLUTIONS

Jupyter Notebook Introductory Session : Beginners to Advance

In [1]:
# The blue color outside the cell re`presents command mode.
# And the green color indicates edit mode.
# Press 'Esc' to get into command mode.
# Press 'Enter' to go back into edit mode.
# Press 'P' to view the list of all available commands.
In [1]:
# This is a coding cell.
# Let's write your first Python program here.

Name = input("Enter your name: ")
print("Hello,", Name)

# Press 'Shift + Enter' to execute the cell.
Enter your name: Karan
Hello, Karan
In [3]:
# Writing comments in a code cell can sometimes creates confusion. Jupyter notebook works both as a notebook and a coding console. 
# To write explanatory texts, you can use a markdown cell which enables you to format your comments well to create a more
# readable code.

# Let's now learn about markdown cells, then.
# Press 'M' in command mode to convert a code cell to a Markdown cell.

This is a Markdown Cell. Double click on a markdown cell or press 'Enter' to see how it's written. And again, press 'Shift + Enter' to execute the cell.

Let's further learn about the various customizations in a markdown cell to create a more readable and understandable code.

This is a title

This is a heading

This is a subheading

This is as small as a heading can get

The fifth hash makes it Italic. Wow!

Formatting in Markdown cells

Emphasis

"Thi/s will appear bold."

"So will this."

"Just one dash makes it italic."

"And one star on either side as well."

"This one's both bold and italic."

Monospace Fonts

Use a back single quotation mark (`) to get monospace fonts.

This text will appear in monospace font. Python is a beautiful language.

Line Breaks

Sometimes in the markdown cells, you don't get a line break where you want simply by pressing enter. In such cases use <br> to get a manual line break.

I want a line break here. But I don't get it. :/
So I used a manual line break
There we go! :)

Indenting

Use > to indent your text.

This is the first line

This indents the second line.

This further indents it.

And this goes on and on.

Bullets and Numbering

  • A dash followed by two spaces, i.e. '- ' creates a bullet.
    • Pressing a tab before doing the above creates a sub-bullet.
  1. Start with a simple 1. (1 followed by a dot and a space) to get a numbered list.
  2. And keep doing it for further numbers.
    1. Again, just a tab for the sub-bullet.

Coloring

  • This text will be blue.
  • I hate this color!

Adding an Image

You can add an image from the web by using <img src = "image_path">

Example:

LaTeX Equations

Jupyter notebook also supports LaTeX equations. Use a $ on either side to write a LaTeX equation.

The below example is just a hypothetical equation to explain how you can write LaTeX equations in Jupyter notebook.

$(\frac{a_1}{a_2} + \frac{a_3}{a_4})^2 = a_5^3$

Go through this link if you want to learn the LaTeX syntax.

Basic Commands

That was all about markdown cells. Now let us take a look at the most useful commands that you require everyday while coding in the Jupyter notebook.

Command Mode Shortcuts

  • Esc: To go into command mode
  • Enter: To go back to edit mode
  • M: To convert a cell to a markdown cell
  • Y: To convert a cell back to a code cell
  • A: To insert new cell above
  • B: To insert new cell below
  • D + D: To delete cell
  • Z: Undo last operation
  • F: To find and replace on your code
  • Shift + Up/Down: To select multiple cells
  • Space: Scroll notebook downwards
  • Shift + Space: Scroll notebook upwards

Edit Mode Shortcuts

  • Shift + Enter: To execute the code in the current cell and go to the next cell
  • Alt + Enter: To execute the code in the current cell and insert new cell below
  • Shift + Tab: To get a brief documentation of the object that you have just typed in the coding cell
  • Ctrl + Shift + -: To split the cell at cursor
  • Shift + M: To merge selected cells

Apart from this, you can also use H to open the list of keyboard shortcuts and even add new shortcuts or customize the existing shorcuts according to your personal requirements.

In [ ]:
 
In [ ]:
 
In [ ]: